<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>add</title>
    {js href='__STATIC__/layui/css/layui.css' /}
    {js href='__STATIC__/jquery/jquery-1.11.0.min.js' /}
    {js href='__STATIC__/layui/layui.all.js' /}
</head>
<style type="text/css">
    .main{width: 98%;margin: 0 auto;}
    .input{width: 60%}
    .selec{width: 30%}
    .imgs{width: 100%;}
    .imgs img{width: 100%;}
</style>
<body>
<div class="main">
    <form class="layui-form">
        <div class="layui-form-item">
            <label class="layui-form-label">真实姓名</label>
            <div class="layui-input-block">
                <input type="text" name="relname" value="{$data.relname}" placeholder="请输入真实姓名" autocomplete="off" class="layui-input input" lay-verify="required" >
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">微信openid</label>
            <div class="layui-input-block">
                <input type="text" name="openid" value="{$data.openid}" placeholder="请输入微信openid" autocomplete="off" class="layui-input input" lay-verify="required" >
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">刮刮乐拍照</label>
            <div class="layui-input-block">
                {:hook('Upload',['type'=>'image','width'=>'200','name'=>'imgurl','value'=>$data.img_url])}
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">中奖金额</label>
            <div class="layui-input-block">
                <input type="text" name="balance" value="{$data.balance}" placeholder="请输入中奖金额" autocomplete="off" class="layui-input input" lay-verify="required|number">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">联系电话</label>
            <div class="layui-input-block">
                <input type="text" name="mobile" value="{$data.mobile}" placeholder="请输入电话" lay-verify="required|phone|number" autocomplete="off" class="layui-input input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">中奖状态</label>
            <div class="layui-input-block selec">
                <select name="status">
                    <option value="0" {if $data.status =='待处理'}selected{/if}>待处理</option>
                    <option value="1" {if $data.status == '中奖'}selected{/if}>中奖</option>
                    <option value="2" {if $data.status == '未中奖'}selected{/if}>未中奖</option>
                    <option value="3" {if $data.status == '错误'}selected{/if}>错误</option>
                    <option value="4" {if $data.status == '已兑奖'}selected{/if}>已兑奖</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formAdd">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
<script>
    //Demo
    layui.use('form', function(){
        var form = layui.form;
        form.render();
        //监听提交
        form.on('submit(formAdd)', function(data){
            data.field.id = {$data.id};
            let fd = data.field
            let imgurl = fd.imgurl
            if(imgurl===''){
                layer.msg('请上传图片')
                return false;
            }

            $.ajax({
                contentType: 'application/json',
                type: 'POST',
                url:"{$editUrl}",
                data:JSON.stringify(data.field),
                dataType:"json",
                success:msg=>{
                    if(msg.code===0){
                        layer.msg('添加成功',{icon: 6},()=>{
                            let page = {$data.page};
                            let limit = {$data.limit};
                            location.href=`{$indexUrl}?page=${page}&limit=${limit}`;
                        });
                    }else{
                        layer.msg('添加失败');
                    }
                }
            })
            return false;
        });
    });
    $('.rhaphp-upload-thumb').on('click',()=>{
        let src = $('.rhaphp-upload-thumb img').attr('src')
        layer.open({
            type:1,
            shade:[0.1,'#ffffff'],
            shadeClose:true,
            content:`<div class="imgs"><img src="${src}"></div>`
        })
    })
</script>
</body>
</html>
